package com.example.mq.kafka.rest;

import com.example.mq.kafka.dataobject.Kafka01Message;
import com.example.mq.kafka.producer.KafkaProducer;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author luowj12
 * @since 2021/4/25 10:42
 */

@Slf4j
@RestController
@RequestMapping("kafka")
@Api(tags="kafka发送消息")
public class KafkaController {

    @Autowired
    KafkaProducer demo01Producer;

    @PostMapping("/syncSend")
    public void send(@RequestBody Kafka01Message Kafka01Message){
        try {
            demo01Producer.syncSend(Kafka01Message.getId());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @PostMapping("/asyncSendPartition")
    public void asyncSendPartition(@RequestBody Kafka01Message Kafka01Message){
        try {
            demo01Producer.asyncSendPartition(Kafka01Message.getId());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
